package com.resLoader
{
	public class ResData
	{
		public static var SWF : String = "swf";
		public static var IMAGE : String = "img";
		public static var TEXT : String = "string";
		public static var XML : String = "xml";
		public static var MP3 : String = "mp3";

		/**
		 *地址
		 */
		public var url : String;
		/**
		 *优先级别
		 */
		public var priority : int;
		/**
		 *下载类型
		 */
		public var type : String;

		public var onCompletes : Array;

		public function ResData(url : String, type : String, priority : int = 0,onComplete : Function = null)
		{
			this.url = url;
			this.type = type;
			this.priority = priority;
			addReturnFun(onComplete);
		}

		public function excute(data : *) : void
		{
			for each(var fun : Function in onCompletes)
			{
				if(fun != null)
				{
					fun(data);
				}
			}
		}

		public function addReturnFun(param : Object) : void
		{
			if(param == null)
			{
				return;
			}

			if(param is Function)
			{
				var fun : Function = param as Function;

				if(onCompletes == null)
				{
					onCompletes = [fun];
				}
				else
				{
					onCompletes.push(fun);
				}
			}
			else if(param is Array)
			{
				if(onCompletes == null)
				{
					onCompletes = param as Array;
				}
				else
				{
					onCompletes = onCompletes.concat(param as Array);
				}
			}
		}

		public function destroy() : void
		{
			if(onCompletes)
			{
				onCompletes.length = 0;
				onCompletes = null;
			}
		}

		public function get isDestroy() : Boolean
		{
			return true;
		}
	}
}